package model

import model.inter.Attackable
import model.inter.Blockable
import model.inter.DestoryAble
import model.inter.Sufferable
import org.itheima.kotlin.game.core.Painter

class Camp:View(),Sufferable,Blockable,DestoryAble{

    /**
     * 生命值为0的时候，销毁；
     */
    override fun isNeedDestory(): Boolean=totalBlood<=0;


    //这里是血量的逻辑；
    override var totalBlood: Int=5


    val blockSize=32;

    //这里是墙的图片；
    val wallImg="img/wall_small.gif"
    //
    val campImg="img/symbol.gif"




    //这里我我们将camp画出来；

    override fun draw() {
        //这里我
        if(totalBlood>1){

            drawWall();
            drawCamp(x+blockSize,y+blockSize);

        }else{
            //这里我们就不需要画墙壁了；
            x=lowBloodX;
            y=lowBloodY;
            drawCamp(x,y)
        }
    }

    private fun drawCamp( x:Int,y:Int) {

        Painter.drawImage(campImg,x,y)

    }

    private fun drawWall() {

        Painter.drawImage(wallImg,x,y)
        Painter.drawImage(wallImg,x+blockSize,y)
        Painter.drawImage(wallImg,x+blockSize*2,y)
        Painter.drawImage(wallImg,x+blockSize*3,y)

        Painter.drawImage(wallImg,x,y+blockSize)
        Painter.drawImage(wallImg,x,y+blockSize*2)


        Painter.drawImage(wallImg,x+blockSize*3,y+blockSize)
        Painter.drawImage(wallImg,x+blockSize*3,y+blockSize*2)
    }

    override fun notifySufferSucceser(attackableView: Attackable): Array<BlastView>? {
        //这里由于我们返回的是一个BlastView，而不是一个数组的，所以这里我们不太好做这个爆炸，效果，
        // 所以这里我们就不做任何操作；
        super.notifySufferSucceser(attackableView)

        if(totalBlood==1){
            return createBoomWallEffect();
        }
        if(totalBlood == 0){
            return createCenterBoom();
        }
        return null
    }

    /**
     * 这里我们需要的效果就是中心爆炸；
     */
    private fun createCenterBoom(): Array<BlastView> {
        return arrayOf(BlastView(lowBloodX,lowBloodY))
    }

    /**
     * 这里是生产一个爆炸的效果；
     */
    private fun createBoomWallEffect(): Array<BlastView> {

        /*
            Painter.drawImage(wallImg,x,y)
            Painter.drawImage(wallImg,x+blockSize,y)
            Painter.drawImage(wallImg,x+blockSize*2,y)
            Painter.drawImage(wallImg,x+blockSize*3,y)

            Painter.drawImage(wallImg,x,y+blockSize)
            Painter.drawImage(wallImg,x,y+blockSize*2)


            Painter.drawImage(wallImg,x+blockSize*3,y+blockSize)
            Painter.drawImage(wallImg,x+blockSize*3,y+blockSize*2)
        */
        //这块确定camp的位置，有时间的话，这块我们是需要商榷的；
        return  arrayOf(
                BlastView(x-blockSize,y),
                BlastView(x-blockSize,y+blockSize),
                BlastView(x-blockSize,y+blockSize*2),

                BlastView(x,y),
                BlastView(x+blockSize,y),
                BlastView(x+blockSize*2,y),
                BlastView(x+blockSize*3,y),

                BlastView(x+blockSize*3,y+blockSize),
                BlastView(x+blockSize*3,y+blockSize*2)
                );
    }



    var lowBloodX=0;
    var lowBloodY=0;


    /**
     * 这里我们创建一个低血量的x,y
     */
    override fun setPostion(col: Double, vol: Double) {
        super.setPostion(col, vol)
        lowBloodX=x+blockSize
        lowBloodY=y+blockSize
    }

}